package com.ic.loan.activity

import android.os.Bundle
import com.blankj.utilcode.util.GsonUtils
import com.gyf.immersionbar.ktx.immersionBar
import com.ic.loan.R
import com.ic.loan.bean.MyInfo
import com.ic.loan.http.ApiUrl
import com.ic.loan.http.HttpUtils
import com.ic.loan.http.ResultListener
import kotlinx.android.synthetic.main.activity_my_info.*

class MyInfoActivity : BaseActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        immersionBar {
            statusBarDarkFont(true)
        }
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_my_info)
        ivBack.setOnClickListener {
            onBackPressed()
        }
        initData()
    }

    private fun initData() {
        showLoading()
        HttpUtils.postOkGo(mutableMapOf("timestamp" to System.currentTimeMillis() / 1000),
            ApiUrl.POST_USER_PROFILE,object : ResultListener() {
            override fun onSucceeded(json: String?) {
                val myInfo = GsonUtils.fromJson(json, MyInfo::class.java)
                edtFirstName.setText(myInfo.fullname)
                edtLastName.setText(myInfo.lastname)
                edtGender.setText(if (myInfo.gender == 1){"Male"}else{"Female"})
                edtBirthday.setText(myInfo.age.toString())
                edtAadharNumber.setText(myInfo.aadhear)
                edtPANCardNumber.setText(myInfo.pan_card_number)
                edtPINCode.setText("")
                edtLoanPurpose.setText("")
                edtEmail.setText(myInfo.email)
            }

            override fun onLoadFinish() {
                hintLoading()
            }
        })
    }
}